package com.aipartner.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * User Entity
 * 
 * @author AI Partner Team
 * @since 2024-01-20
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("users")
public class User {
    
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;
    
    @TableField("open_id")
    private String openid;
    
    @TableField("union_id")
    private String unionId;
    
    @TableField("nick_name")
    private String nickname;
    
    @TableField("avatar_url")
    private String avatarUrl;
    
    @TableField("gender")
    private Integer gender;
    
    @TableField("country")
    private String country;
    
    @TableField("province")
    private String province;
    
    @TableField("city")
    private String city;
    
    @TableField("vip_level")
    private Integer vipLevel;
    
    @TableField("vip_expire_time")
    private LocalDateTime vipExpireTime;
    
    @TableField("balance")
    private Double balance;

    /**
     * 用户当前积分
     */
    @TableField("credits")
    private Long credits;

    /**
     * 累计获得积分
     */
    @TableField("total_credits_earned")
    private Long totalCreditsEarned;

    /**
     * 累计消耗积分
     */
    @TableField("total_credits_consumed")
    private Long totalCreditsConsumed;

    /**
     * 积分最后更新时间
     */
    @TableField("credits_updated_time")
    private LocalDateTime creditsUpdatedTime;
    
    @TableField("status")
    private Integer status;
    
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    
    @TableLogic
    @TableField("deleted")
    private Boolean isDeleted;
    
    /**
     * Check if user is VIP and not expired
     */
    public Boolean isVip() {
        if (vipLevel == null || vipLevel <= 0) {
            return false;
        }
        if (vipExpireTime == null) {
            return false;
        }
        return LocalDateTime.now().isBefore(vipExpireTime);
    }
}